Ext.onReady(function() {
	var toolbar = Ext.create('Ext.toolbar.Toolbar', {
			dock : 'top',
			items : [{
				text : '新建',
				xtype : 'button',
				listeners : {
					click : function() {
						location.href = "/wuziMgr/add_device_acceptance";
					}
				}
			},{
				text : '删除',
				xtype : 'button',
				listeners : {
					click : function() {

						var grid = Ext.getCmp("device_grid");
						var selectionModel = grid.getSelectionModel();
						var models = selectionModel.getSelection();
						var ids = [];
						for (var i = 0; i < models.length; i++) {
							ids[i] = models[i].get("Id");
						}
						Ext.Ajax.request({
									url : '/device_acceptance/delete',
									type : 'POST',
									params : {
										ids : ids
									},
									callback : function(options, success, response) {
										if (success) {
											var result = Ext.decode(response.responseText);
											if (result.success) {
												Ext.getCmp("device_grid").getStore().reload();
											} else {
												Ext.Msg.alert('错误', result.msg);
											}
										}
									}
								});
						}
				}
			},{
				xtype: 'button',
				text: '刷新',
				listeners: {
					click: function(){
						Ext.getCmp("device_grid").getStore().reload();
					}
				}
			}]
		});

	var store = Ext.create('Ext.data.Store', {
				fields : ['Id', 'Device.TdCode', 'Device.No', 'Device.Brand', 'Device.Manufacturers', 'Device.Model', 'Device.OperationTime', 'State'],
				autoLoad : true,
				pageSize: 25,
				proxy : {
					type : 'ajax',
					url : '/device_acceptance/all',
					reader : {
						type : 'json',
						root : 'data.rows',
						totalProperty: 'data.total'
					}
				}
			});
	
	var grid = Ext.create('Ext.grid.Panel', {
				id : "device_grid",
				selType : 'checkboxmodel',
				margin : '5 5',
				store : store,
				columns : [{text : '序号',
							xtype : 'rownumberer',
							width : 40,
							sortable : false
						},{
							text: '二维码',
							flex: 1,
							dataIndex: 'Device.TdCode'
						}, {
							text : '设备编号',
							flex : 1,
							dataIndex : 'Device.No'
						}, {
							text : '设备品牌',
							flex : 1,
							dataIndex : 'Device.Brand'
						}, {
							text : '设备厂家',
							flex : 1,
							dataIndex : 'Device.Manufacturers'
						}, {
							text : '设备型号',
							flex : 1,
							dataIndex : 'Device.Model'
						}, {
							text : '投运时间',
							flex : 1,
							dataIndex : 'Device.OperationTime',
							renderer : function(v) {
								return v;
							}
						}, {
							text : '设备状态',
							flex : 1,
							dataIndex : 'State',
							renderer : function(v) {
								if (v == 0) {
									return '<span style="color:green">验收通过</span>';
								} else {
									return '<span style="color:red">验收失败</span>';
								} 
							}
						}, {
							text : '详细',
							flex : 1,
							renderer : function(v, metaData, record) {
								return '<a href="device_acceptance/detail/'
										+ record.get("Id")
										+ '" style="color:blue;">详细</a>';
							}
						}],
						bbar : Ext.create('Ext.PagingToolbar', {
							store : store,
							border: false,
							displayInfo : true,
							displayMsg : '显示{0} - {1} / 总数 {2}',
							emptyMsg : "没数据"
						})
			});
	var panel = Ext.create("Ext.panel.Panel", {
				title : '',
				border : false,
				bodyBorder : false,
				layout : 'fit',
				dockedItems : [toolbar],
				items : [grid]
			});
	Ext.create('Ext.Viewport', {
				layout : 'fit',
				style : 'background:none;background-color:white;',
				items : [panel]
			});
});
